package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.clqteam.model.Employee;
import com.clqteam.service.employeeLoginService;
import com.clqteam.serviceimpl.employeeLoginServiceImpl;
/**
 * 
 * @author CLQ
 *
 */
public class EmployeeLoginController extends HttpServlet{
	 employeeLoginService emService=new employeeLoginServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	   doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	req.setCharacterEncoding("utf8");
    	resp.setCharacterEncoding("utf8");
    	String name=req.getParameter("inputName");
  	    String psw= req.getParameter("inputPsw");
  	    
  	    Employee em= emService.findEmployeeAccountAndEmployeePsw(name, psw);
  	    HttpSession session=req.getSession();
  	   PrintWriter pw=resp.getWriter();
  	     if(em.geteId()>0){
  	    	   //将用户信息放入session 中
  	    	   session.setAttribute("employee", em);
  	    	   pw.write("1");
  	     }else{
  	    	 pw.write("0");
  	     }
  	    pw.flush();
  	    pw.close();
    	
    }
}
